<%--
  Created by IntelliJ IDEA.
  User: 96394
  Date: 2019/12/23
  Time: 16:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
    <title>下属任务</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/css/base.css" />
    <link rel="stylesheet" href="/css/base/base.css?20201106.1" />
    <link rel="stylesheet" href="/css/news/center.css" />
    <link rel="stylesheet" href="/lib/bootstrap/3.3.7/css/bootstrap.css">
    <script src="/js/news/jquery-1.9.1.js"></script>
    <script src="/js/base/tablePage.js"></script>
    <script src="/js/news/page.js"></script>
    <script src="/js/base/base.js"></script>
    <script src="/lib/bootstrap/3.3.7/js/bootstrap.js"></script>
    <script src="/lib/bootstrap/3.3.7/js/bootstrap-treeview.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/highcharts.js"></script>
    <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
    <!--[if lt IE 9]>
    <script src="/lib/bootstrap/3.3.7/js/html5shiv.min.js"></script>
    <script src="/lib/bootstrap/3.3.7/js/respond.min.js"></script>
    <![endif]-->

    <link rel="stylesheet" href="/css/task/message.css">

    <style>
        * {
            font-family: "Microsoft Yahei";
        }

        *::-webkit-scrollbar {
            width: 6px;
            height: 6px;
        }

        *::-webkit-scrollbar-thumb {
            border-radius: 6px;
            box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.1);
            background: #828080;
            -webkit-border-radius: 6px;
            -moz-border-radius: 6px;
            -ms-border-radius: 6px;
            -o-border-radius: 6px;
        }

        *::-webkit-scrollbar-thumb:hover {
            background: #535353;
        }

        *::-webkit-scrollbar-track {
            border-radius: 6px;
            background: transparent;
            -webkit-border-radius: 6px;
            -moz-border-radius: 6px;
            -ms-border-radius: 6px;
            -o-border-radius: 6px;
        }

        body,
        html {
            width: 100%;
            height: 100%;
            user-select: none;
        }

        .content_wrapper {
            width: 100%;
            height: 100%;
        }

        .c_left {
            position: relative;
            float: left;
            width: 240px;
            height: 100%;
        }

        .c_right {
            position: relative;
            min-width: 360px;
            height: 100%;
            margin-left: 240px;
            border-left: 1px solid #cfdbe2;
        }

        .r_wrapper {
            position: absolute;
            top: 50px;
            right: 0;
            bottom: 0;
            left: 0;
            padding: 10px;
            background-color: #e8edf7;
        }

        .r_box {
            position: relative;
            width: 100%;
            height: 100%;
            padding: 10px;
            background: #fff;
            overflow: auto;
        }

        .c_title {
            height: 50px;
            padding: 10px 20px;
            border-bottom: 1px solid #cfdbe2;
        }

        .c_title h4{
            float: left;
            margin: 0;
            font-size: 14px;
            line-height: 30px;
            font-weight: 500;
        }

        .c_title .tool_bar {
            float: right;
            line-height: 28px;
        }

        .search_box {
            float: left;
            margin-right: 10px;
            color: #757575;
            border-bottom: 1px solid #e0e0e0;
        }

        .search_box .search_input {
            width: auto;
            border: none;
            font-size: 12px;
        }

        .table tr {
            border-left: none;
            border-right: none;
        }

        .table tr input {
            margin: 0;
        }
        .table tr td {
            font-size: 14px;
        }
        .table th {
            font-size: 14px;
            font-weight: 600;
            line-height: 30px;
            vertical-align: middle !important;
        }

        .pagination-box {
            text-align: center;
            float: right;
        }

        .pagination-box a {
            cursor: pointer;
        }

        .pagination-box .disable>a {
            background-color: #bdbdbd !important;
            color: #696969 !important;
            cursor: default;
        }

        .pagination {
            margin: 2px 0;
        }

        .total-box {
            position: relative;
            display: inline-block;
            margin: 2px 0;
            vertical-align: top;
            padding: 3px 12px;
            line-height: 1.42857143;
            color: #000;
            background-color: #fff;
        }
        .total-box>span {
            margin-right: 10px;
        }

        .total-box>input{
            width: 35px;
            padding: 0 2px;
            text-align: center;
            background-color: #ccc;
            border-radius: 5px;
        }

        .total-box .btnpage {
            margin-left: 5px;
            padding: 0 3px;
            border-radius: 5px;
            background: #ffa500;
            color: #231d1d;
        }

        #urgeModal .clear_users {
            font-size: 12px;
            float: left;
            /*height: 100%;*/
            padding: 3px 10px;
            margin-top: 0px;
            line-height: 16px;
            border: 1px solid;
            border-radius: 15px;
            -webkit-border-radius: 15px;
            -moz-border-radius: 15px;
            -ms-border-radius: 15px;
            -o-border-radius: 15px;
        }

        #urgeModal .clear_users:hover {
            color: #3da8f5;
            border-color: #3da8f5;
        }

        #urgeModal .hr_line {
            float: left;
            border: 1px solid;
            height: 24px;
            margin: 0px 8px 0;
        }

        .creator_box .creator_name {
            display: inline-block;
            position: relative;
            padding: 5px 18px 5px 15px;
            margin-right: 5px;
            margin-bottom: 10px;
            border-radius: 15px;
            background: #e8e8e8;
            color: #333;
            line-height: 16px;
            cursor: pointer;
        }

        .creator_box .creator_name .remove_user {
            visibility: hidden;
            position: absolute;
            top: 7px;
            right: 4px;
            font-size: 12px;
            font-weight: 400;
            cursor: pointer;
        }

        .creator_box .icon-change-creator {
            margin-top: 5px;
            margin-left: 5px;
            text-align: center;
            color: #b3b2b2;
            cursor: pointer;
        }

        .creator_box .icon-change-creator:hover {
            border-color: #0aa3e3;
            color: #0aa3e3;
        }

        .creator_name:hover .remove_user {
            visibility: visible;
        }

        .hide_btn {
            opacity: 0;
            position: absolute;
            top: 50%;
            left: 3px;
            margin-top: -7px;
            cursor: pointer;
        }
        .c_title:hover .hide_btn {
            opacity: 1;
        }

        #subordinate_tree {
            position: absolute;
            top: 50px;
            bottom: 0;
            width: 100%;
            overflow: auto;
        }
    </style>
</head>
<body>
<div class="content_wrapper ">
    <div class="c_left">
        <div class="c_title">
            <h4>我的下属</h4>
        </div>
        <div id="subordinate_tree"></div>
    </div>
    <div class="c_right">
        <div class="c_title" style="position: relative;">
            <span class="glyphicon glyphicon-chevron-left hide_btn hide_left"></span>
            <span class="glyphicon glyphicon-chevron-right hide_btn show_left" style="display: none;"></span>
            <h4>任务列表</h4>
            <div class="tool_bar">
<%--                <div class="search_box">--%>
<%--                    <input type="text" class="search_input" placeholder="搜索">--%>
<%--                    <span class="glyphicon glyphicon-search"></span>--%>
<%--                </div>--%>
                <button class="btn btn-default btn-xs btn_export">导出</button>
            </div>
        </div>
        <div class="r_wrapper">
            <div class="r_box">
                <table class="table table-striped r_table">
                    <thead>
                        <tr>
                            <th style="width: 65px"><input type="checkbox" id="sellectAll" name="sellectAll">全选</th>
                            <th style="width: 65px">关注</th>
                            <th style="width: 340px;min-width: 280px">任务名称</th>
                            <th style="min-width: 120px">负责人</th>
                            <th style="min-width: 80px">评分</th>
                            <th style="min-width: 90px">子任务</th>
                            <th style="min-width: 100px">结束日期</th>
                            <th style="min-width: 90px">进度</th>
                            <th style="min-width: 90px">完成情况</th>
                            <th style="min-width: 125px">操作</th>
                        </tr>
                    </thead>
                    <tbody id="table_body">

                    </tbody>
                </table>
                <div class="r_bottom">
                    <div class="btn-group" role="group" aria-label="...">
                        <button type="button" class="btn btn-default btn_urges">批量催办</button>
                        <button type="button" class="btn btn-default btn_mark">批量关注</button>
                    </div>
                    <nav class="pagination-box" id="pagination">

                    </nav>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 设置评分弹窗 -->
<div class="modal-body" id="gradeModal" style="display: none;">
    <form class="form-horizontal">
        <div class="form-group">
            <label class="col-sm-4 control-label">设置评分</label>
            <div class="col-sm-7">
                <input class="form-control task_grade" type="number"/>
            </div>
        </div>
    </form>
</div>

<!-- 设置任务催办弹窗 -->
<div class="modal-body" id="urgeModal" style="display: none;">
    <form class="form-horizontal">
        <div class="form-group">
            <label class="col-sm-3 control-label">催办内容</label>
            <div class="col-sm-8">
                <textarea class="form-control urge_content" rows="2" placeholder="催办内容" style="border: 1px solid;resize: none;">这个任务需要抓紧处理</textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">提醒给</label>
            <div class="col-sm-8">
                <label class="checkbox-inline">
                    <input type="checkbox" style="margin-top: -1px;" class="remind" value="1" checked> 负责人
                </label>
                <label class="checkbox-inline">
                    <input type="checkbox" style="margin-top: -1px;" class="remind" value="2"> 参与人
                </label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">其他人</label>
            <div class="col-sm-7">
                <textarea id="other_users" user_id="" class="form-control" disabled readonly="readonly" rows="2" style="border: 1px solid;resize: none;"></textarea>
            </div>
            <div class="col-sm-2" style="padding-top: 5px; padding-left: 0;">
                <a href="javascript:;" class="add_other_users" style="display: block; color: blue;text-decoration: none;">添加</a>
                <a href="javascript:;" class="clear_other_users" style="display: block; color: red;text-decoration: none;">清空</a>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">提醒方式</label>
            <div class="col-sm-8">
                <label class="checkbox-inline">
                    <input type="checkbox" style="margin-top: -1px;" value="1" class="reminder" name="reminder" checked> 内部消息
                </label>
                <label class="checkbox-inline">
                    <input type="checkbox" style="margin-top: -1px;" value="2" class="reminder" name="reminder"> 手机短信
                </label>
            </div>
        </div>
    </form>
</div>

</body>
<script src="/js/task/message.js"></script>
<script src="/js/task/pagination.js"></script>
<script type="text/javascript">
    var user_id = '';
    $(function(){
        var basePath = "<%=basePath%>";
        var info = {
            users: {},
            pagination: {
                page: 1,
                pageSize: 10,
                totalCount: 0,
                onClick: function (page) {
                    info.getSubordinateTask(page);
                }
            },
            // 获取下属任务列表
            getSubordinateTask: function (page,userId,deptId) {
                var h = this;

                $.get(basePath+"taskSubordinate/querySubordinateTask", {pageSize: 10,userId:userId,deptId:deptId, page: page, useFlag: true, temp: 0}, function(res){
                    if (res.flag) {
                        var $tBody = $('#table_body');
                        var $pagination = $('#pagination');
                        $pagination.empty();
                        $tBody.empty();
                        $('#sellectAll').prop('checked', false);
                        h.pagination.page = page;
                        h.pagination.totalCount = res.totleNum;
                        $('#pagination').pagination(h.pagination);
                        res.obj.forEach(function(item){
                            var followStr = '';
                            var btnAttention = '<button type="button" class="btn btn-default btn-xs btn_attention" data-type="1">关注</button>';
                            if (item.follow == 1) {
                                followStr = '<span class="glyphicon glyphicon-star-empty" style="margin-top: 3px;"></span>';
                                btnAttention = '<button type="button" class="btn btn-default btn-xs btn_attention" data-type="2">取消关注</button>'
                            }

                            var urgeBtn = '';
                            var checkStr = ''

                            if (item.taskStatus == 0) {
                                urgeBtn = '<button type="button" class="btn btn-default btn-xs btn_urge">催办</button>';
                                checkStr = '<input class="selectBox" type="checkbox" name="selectBox">';
                            } else {
                                btnAttention = '';
                            }

                            var $trItem = $('<tr>\n' +
                                '                            <td>'+checkStr+'</td>' +
                                '                            <td>'+followStr+'</td>' +
                                '                            <td>'+item.taskName+'</td>' +
                                '                            <td>'+item.manageUserName+'</td>' +
                                '                            <td>'+item.taskGrade+'</td>' +
                                '                            <td>'+item.completedCount+'/'+item.taskCount+'</td>' +
                                '                            <td>'+item.startDate.split(" ")[0]+'</td>' +
                                '                            <td>'+item.progress+'%</td>' +
                                '                            <td>'+(item.taskStatus == 0 ? "未完成" : "已完成")+'</td>' +
                                '                            <td><div class="btn-group">' + urgeBtn +
                                '  <button type="button" class="btn btn-default btn-xs btn_grade">评分</button>' + btnAttention +
                                '</div></td>' +
                                '                        </tr>');
                            $trItem.data('taskInfo', item);
                            $tBody.append($trItem);
                        });
                    }
                });
            },
            getTreeList: function (arr, result) {
                var h = this;
                arr.forEach(function(dept) {
                    var item = { id: dept.deptId, deptId: dept.deptId, pId: dept.deptParent, text: dept.deptName, users: dept.users }
                    result.push(item);
                    if (dept.child) {
                        h.getTreeList(dept.child, result);
                    }
                });
                return result;
            },
            getTree: function (data, children = 'nodes', pid = 'pId', id = 'deptId') {
                var h = this;
            // 深克隆，防止改变原数组
            var treeData = JSON.parse(JSON.stringify(data))

            treeData = treeData.filter(parent => {

                var branchArr = treeData.filter(child => {

                    if (child[pid] == parent[id]) {
                        return child
                    }

                })

                if (h.users[parent.deptId]) {
                    for (var user in h.users[parent.deptId]) {
                        branchArr.unshift(h.users[parent.deptId][user])
                    }
                }

                if (branchArr.length > 0) {
                    parent[children] = branchArr
                }

                // 返回根节点
                if (parent.pId == 0) {
                    return parent
                }

            })

            return treeData

        },
            tableEvents: function(){
                var h = this;

                //列表-导出
                $('.btn_export').on('click', function(){
                    window.location.href = basePath+'taskSubordinate/querySubordinateTask?useFlag=false&temp=1'
                });

                // 批量关注
                $('.btn_mark').on('click', function(){
                    var $checks = $("input[name='selectBox']:checkbox:checked");

                    if ($checks.length == 0) {
                        layer.msg('请选择需要操作的数据')
                        return false;
                    }

                    var ids = [];
                    $checks.each(function(item){
                        var taskInfo = $(this).parents('tr').data('taskInfo');
                        ids.push(taskInfo.taskId)
                    });

                    $.post('/taskSubordinate/batchattentionTask', {taskId: ids.join(',')}, function(res){
                        if(res.flag) {
                            $('#table_body').empty();
                            h.getSubordinateTask(1);
                        }
                    })
                });

                // 批量催办
                $('.btn_urges').on('click', function(){
                    var _this = this;

                    var $checks = $("input[name='selectBox']:checkbox:checked");

                    if ($checks.length == 0) {
                        layer.msg('请选择需要操作的数据');
                        return false;
                    }

                    var taskIds = '';
                    $checks.each(function(){
                        var taskInfo = $(this).parents('tr').data('taskInfo');
                        taskIds = taskIds + taskInfo.taskId + ',';
                    });

                    batchUrge(taskIds);
                });

                // 催办选择其他用户
                $('.add_other_users').on('click', function(){
                    user_id='other_users';
                    $.ajax({
                        url:'/imfriends/getIsFriends',
                        type:'get',
                        dataType:'json',
                        data:{},
                        success:function(obj){
                            if(obj.object == 1){
                                $.popWindow("../common/selectUserIMAddGroup");
                            }else{
                                $.popWindow("../common/selectUser");
                            }
                        },
                        error:function(res){
                            $.popWindow("../common/selectUser");
                        }
                    })
                });
                // 催办清空其他用户
                $('.clear_other_users').on('click', function(){
                    $('#other_users').get(0).setAttribute('user_id', '');
                    $('#other_users').val('');
                });

            },
            events: function(){
                var h = this;

                //头部-全选
                $('.r_table').on('click', '#sellectAll', function() {
                    var checkedOfAll=$("#sellectAll").prop("checked");
                    $(".selectBox").prop("checked", checkedOfAll);
                });

                //列表-单选
                $('.r_table').on('click', '.selectBox', function() {
                    var $this = $(this);
                    if ($this.checked == false) {
                        $("#sellectAll").prop('checked', false);
                    } else {
                        var count = $("input[name='selectBox']:checkbox:checked").length;
                        if (count == $(".selectBox").length) {
                            $("#sellectAll").prop("checked", true);
                        }else{
                            $("#sellectAll").prop("checked", false);
                        }
                    }
                });

                //列表-催办
                $('.r_table').on('click', '.btn_urge', function(){
                    var taskInfo = $(this).parents('tr').data('taskInfo');
                    batchUrge(taskInfo.taskId+',');
                });

                //列表-评分
                $('.r_table').on('click', '.btn_grade', function(){
                    var _this = this;
                    var taskInfo = $(_this).parents('tr').data('taskInfo');
                    $('.task_grade').val(taskInfo.taskGrade);
                    layer.open({
                        title : "评分",
                        type: 1,
                        area : [ '300px', '230px' ],
                        btn: ['确定', '取消'],
                        content: $('#gradeModal'),
                        yes: function(){
                            var taskGrade = $('.task_grade').val();
                            if (taskGrade > 100) {
                                layer.msg('评分不能大于100');
                                return false;
                            }
                            var data = {
                                taskId: taskInfo.taskId, // 任务主键id
                                taskName: taskInfo.taskName, // 任务名称
                                taskDesc: taskInfo.taskDesc || '', // 任务详情
                                importantLevel: parseInt(taskInfo.importantLevel), //重要程度 0普通 1重要 2紧急 传数字类型
                                createUser: taskInfo.createUser, // 创建人
                                manageUser: taskInfo.manageUser, //负责人
                                taskStatus: taskInfo.taskStatus, //任务状态
                                createDate: taskInfo.createDate ? taskInfo.createDate.split(' ')[0] : '', //创建时间
                                startDate: taskInfo.startDate ? taskInfo.startDate.split(' ')[0] : '', //开始时间
                                endDate: taskInfo.endDate ? taskInfo.endDate.split(' ')[0] : '', //结束时间
                                parentId: taskInfo.parentId, //父任务Id
                                progress: taskInfo.progress, //任务进度 传数字类型
                                taskGrade: parseInt(taskGrade), // 评分
                                completeDate: taskInfo.completeDate ? taskInfo.completeDate.split(' ')[0] : '', // 完成日期
                                typeId: taskInfo.typeId, //任务类型id
                                attachmentId: taskInfo.attachmentId || '', // 附件id
                                attachmentName: taskInfo.attachmentName || '', // 附件名字
                                participate: taskInfo.participate, //参与者 拼接用户id用，连接
                                shared: taskInfo.shared,//共享者 拼接用户id用，连接
                                follow: taskInfo.follow//是否关注  取消关注2 关注1 默认0
                            }
                            $.ajax({
                                url: '/task/updateTaskManage',
                                type: 'post',
                                dataType: 'json',
                                data: data,
                                success: function(res){
                                    if (res.flag) {
                                        layer.msg('评分成功');
                                        layer.closeAll();
                                        $('#table_body').empty();
                                        h.getSubordinateTask(1);
                                    } else {
                                        layer.msg('评分失败')
                                    }
                                }
                            });
                        },
                        btn2: function(){
                            $('.task_grade').val(0);
                        }
                    });
                });

                //列表-关注
                $('.r_table').on('click', '.btn_attention', function(){
                    var _this = this;
                    var taskInfo = $(_this).parents('tr').data('taskInfo');
                    var follow = parseInt($(this).data('type'));

                    var data = {
                        taskId: taskInfo.taskId, // 任务主键id
                        taskName: taskInfo.taskName, // 任务名称
                        taskDesc: taskInfo.taskDesc || '', // 任务详情
                        importantLevel: parseInt(taskInfo.importantLevel), //重要程度 0普通 1重要 2紧急 传数字类型
                        createUser: taskInfo.createUser, // 创建人
                        manageUser: taskInfo.manageUser, //负责人
                        taskStatus: taskInfo.taskStatus, //任务状态
                        createDate: taskInfo.createDate || '', //创建时间
                        startDate: taskInfo.startDate || '', //开始时间
                        endDate: taskInfo.endDate || '', //结束时间
                        parentId: taskInfo.parentId, //父任务Id
                        progress: taskInfo.progress, //任务进度 传数字类型
                        taskGrade: taskInfo.taskGrade, // 评分
                        completeDate: taskInfo.completeDate || '', // 完成日期
                        typeId: taskInfo.typeId, //任务类型id
                        attachmentId: taskInfo.attachmentId || '', // 附件id
                        attachmentName: taskInfo.attachmentName || '', // 附件名字
                        participate: taskInfo.participate, //参与者 拼接用户id用，连接
                        shared: taskInfo.shared,//共享者 拼接用户id用，连接
                        follow: follow//是否关注  取消关注0 关注1 默认0
                    }
                    $.ajax({
                        url: '/task/updateTaskManage',
                        type: 'post',
                        dataType: 'json',
                        data: data,
                        success: function(res){
                            if (res.flag) {
                                layer.msg('操作成功');
                                if (follow == 1) {
                                    $(_this).parents('tr').children('td').eq(1).append($('<span class="glyphicon glyphicon-star-empty" style="margin-top: 3px;"></span>'));
                                    $(_this).replaceWith($('<button type="button" class="btn btn-default btn-xs btn_attention" data-type="2">取消关注</button>'));
                                } else {
                                    $(_this).parents('tr').children('td').eq(1).empty();
                                    $(_this).replaceWith($('<button type="button" class="btn btn-default btn-xs btn_attention" data-type="1">关注</button>'));
                                }

                            } else {
                                layer.msg('操作失败')
                            }
                        }
                    });
                });
            },
            init: function(){
                var h = this;

                h.getSubordinateTask(1);

                // 获取下属列表
                $.get(basePath+'taskSubordinate/querySubordinate', function(res){
                    if (res.flag) {
                        res.obj.forEach(function(user){
                            var avatar = user.avatar;
                            if (avatar == undefined || avatar == "") {
                                avatar = user.sex;
                            }
                            if (avatar == 0) {
                                avatar = '/img/email/icon_head_man_06.png'
                            } else if (avatar == 1) {
                                avatar = '/img/email/icon_head_woman_06.png'
                            } else {
                                avatar = '/img/user/' + user.avatar
                            }
                            if (!h.users[user.deptId]) {
                                h.users[user.deptId] = {}
                            }
                            h.users[user.deptId][user.userId] = {userId: user.userId, deptId: user.deptId, text: '<img src='+avatar+' style="width: 27px;margin: -4px 5px 0 0; border-radius: 50%;" >'+user.userName+'', isTitle: true, itemTitle: user.userName}
                        });
                        $.get('/task/queryUser', function(res){

                            if (res.flag) {
                                $.get('/department/getNewChAllDept', {deptId: res.data.deptId}, function(res){
                                    if (res.flag) {
                                        var treedata = h.getTree(h.getTreeList([res.object], []));
                                        // 生成左侧下属列表树
                                        $('#subordinate_tree').treeview({
                                            expandIcon: 'glyphicon glyphicon-chevron-right',
                                            collapseIcon: 'glyphicon glyphicon-chevron-down',
                                            showBorder: false,
                                            highlightSelected: false,
                                            levels: 7,
                                            data: treedata,
                                            onNodeSelected: function(event, data) {
                                                if(data.nodes!=null){
                                                    var select_node = $('#subordinate_tree').treeview('getSelected');
                                                    if(select_node[0].state.expanded){
                                                        $('#subordinate_tree').treeview('collapseNode',select_node);
                                                        select_node[0].state.selected=false;
                                                    }
                                                    else{
                                                        $('#subordinate_tree').treeview('expandNode',select_node);
                                                        select_node[0].state.selected=false;
                                                    }
                                                }
                                            }, onNodeSelected: function(event, data) {
                                                info.getSubordinateTask('',data['userId'],data['deptId'])
                                            }
                                        });
                                    }
                                });
                            }
                        });
                    }
                });

                h.tableEvents();

                h.events();

                var screenwidth = document.documentElement.clientWidth;
                if(screenwidth > 1550){
                    var nums = screenwidth*0.9;
                }else{
                    var nums = 1120;
                }
                var width1 = nums*0.06+'px';
                var width2 = nums*0.230+'px';

                $('th').each(function(index){
                    switch (index) {
                        case 0:
                            $(this).css({'width': width1})
                            break;
                        case 1:
                            $(this).css({'width': width1})
                            break;
                        case 2:
                            $(this).css({'width': width2})
                            break;
                        case 6:
                            $(this).css({'width': '100px'})
                            break;
                        case 9:
                            $(this).css({'width': '148px'});
                            break;
                        default:
                            $(this).css({'width': '90px'})
                            break;
                    }
                });
            }
        }

        info.init();

        // 催办弹窗
        function batchUrge (taskIds) {
            layer.open({
                title: '催办设置',
                type: 1,
                area: ['500px', '360px'],
                btn: ['确定', '取消'],
                content: $('#urgeModal'),
                yes: function(){
                    var urgeContent = $('.urge_content').val().trim();
                    var remind = $('.remind:checked');
                    var otherPeople = $('#other_users').attr('user_id') || '';
                    var reminder =$('.reminder:checked');

                    if (remind.length > 1) {
                        remind = '1,2';
                    } else if (remind.length == 1) {
                        remind = remind.val()
                    }

                    if (otherPeople.length == 0) {
                        otherPeople = '';
                    }

                    if (reminder.length > 1) {
                        reminder = '1,2';
                    } else if (reminder.length == 1) {
                        reminder = reminder.val();
                    }

                    var data = {
                        taskId: taskIds,
                        urgeContent: urgeContent,
                        remind: remind,
                        otherPeople: otherPeople,
                        reminder: reminder
                    }
                    if(remind == '2' || remind == '1,2'){
                        // console.log('lll')
                        // console.log($('#other_users').val())
                        if($('#other_users').val() == ''){
                            $.layerMsg({content: '请添加参与人员！', icon: 2});
                            return false
                        }

                    }
                    $.post(basePath+'task/batchUrgeTask', data, function(res){
                        if (res.flag){
                            layer.closeAll();
                            $('.urge_content').val('这个任务需要抓紧处理');
                            $('.remind').prop('checked', false);
                            $('.remind').eq(0).prop('checked', true);
                            $('#other_users').get(0).setAttribute('user_id', '');
                            $('#other_users').val('');
                            $('.reminder').prop('checked', false);
                            $('.reminder').eq(0).prop('checked', true);
                        }
                    });
                },
                btn2: function(){
                    $('.urge_content').val('这个任务需要抓紧处理');
                    $('.remind').prop('checked', false);
                    $('.remind').eq(0).prop('checked', true);
                    $('#other_users').attr('user_id', '');
                    $('#other_users').val('');
                    $('.reminder').prop('checked', false);
                    $('.reminder').eq(0).prop('checked', true);
                },
                cancel: function(){
                    $('.urge_content').val('这个任务需要抓紧处理');
                    $('.remind').prop('checked', false);
                    $('.remind').eq(0).prop('checked', true);
                    $('#other_users').attr('user_id', '');
                    $('#other_users').val('');
                    $('.reminder').prop('checked', false);
                    $('.reminder').eq(0).prop('checked', true);
                }
            });
        }

        //监听键盘事件，number输入框只能输入数字
        $(document).on('keypress', 'input[type=number]', function(e){

            var key = window.event ? e.keyCode : e.which

            if (!((key > 95 && key < 106) || (key > 47 && key < 58) || key == 8 || key == 9 || key == 13 || key == 37 || key == 39)) {
                return false
            }
        });
        // 监听number输入框值不能小于0，不能大于100
        $(document).on('input propertychange', 'input[type=number]', function(){
            var val = parseInt($(this).val())
            if (val <= 0) {
                $(this).val(0);
            } else if (val > 100) {
                $(this).val(100);
            }
        });

        // 点击隐藏下属列表
        $('.hide_left').on('click', function(){
            $(this).hide();
            $('.show_left').show();
            $('.c_left').hide();
            $('.c_right').css('margin-left', '0');
        });

        // 点击显示下属列表
        $('.show_left').on('click', function(){
            $(this).hide();
            $('.hide_left').show();
            $('.c_left').show();
            $('.c_right').css('margin-left', '240px');
        });

    })
</script>
</html>
